package com.example.babara.memo.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.babara.memo.R;
import com.example.babara.memo.pojo.Memo;

import java.util.List;

/**
 * Created by babara on 2017/4/3.
 */

public class MemoAdapter extends ArrayAdapter<Memo> {
    private TextView startHour;
    private TextView startMin;

    private int textViewResource;
    public MemoAdapter(Context context, int textViewResource, List<Memo> objects){
        super(context, textViewResource, objects);
        this.textViewResource = textViewResource;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        Memo memo = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(textViewResource, null);
        startHour = (TextView)view.findViewById(R.id.hour_text);
        startMin = (TextView)view.findViewById(R.id.min_text);
        TextView scopeText = (TextView)view.findViewById(R.id.scope_text);
        TextView cardText = (TextView)view.findViewById(R.id.card_text);
        TextView remarkText = (TextView)view.findViewById(R.id.remark_text);
        TextView repeatText = (TextView)view.findViewById(R.id.repeat_text);
        setTimeFormat(memo.getStartHour(), memo.getStartMin());
        scopeText.setText(memo.getScope());
        cardText.setText(memo.getCard());
        remarkText.setText(memo.getRemark());
        repeatText.setText(memo.getRepeat());

        return view;
    }

    public void setTimeFormat(int hour, int min){
        String hourStr = String.valueOf(hour);
        String minStr = String.valueOf(min);
        if(hour < 10){
            hourStr = "0" + hourStr;
        }
        if(min < 10){
            minStr = "0" + minStr;
        }
        startHour.setText(hourStr);
        startMin.setText(minStr);
    }
}
